package com.zhao.controller;

import com.zhao.pojo.Purchase;
import com.zhao.pojo.Sale;
import com.zhao.service.Impl.SaleServiceImpl;
import com.zhao.vo.SaleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/sale")
public class SaleController {
    @Autowired
    SaleServiceImpl saleService;
    @RequestMapping("/toList")
    public String toList(Model model){
        List<Sale> sales = saleService.selectAllSale();
        model.addAttribute("sale",sales);
        return "sale/list";
    }
    @RequestMapping("/toAdd/{id}")
    public String toAdd(@PathVariable("id") int id, Model model){
        Sale sale = saleService.selectSaleById(id);
        model.addAttribute("sale",sale);
        return "sale/add";
    }
    @RequestMapping("/add")
    public String add(SaleVo saleVo){
        saleService.updateSale(saleVo);
        return "redirect:/sale/toList";
    }
}
